<%-- 
    Document   : addCategory
    Created on : Nov 3, 2011, 1:41:46 AM
    Author     : Admin
--%>

<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categorybean.Category"%>
<%@page import="categorybean.CategoryHome"%>
<%@page import="GoodsBean.Goods"%>
<%@page import="GoodsBean.GoodsHome"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="DBConnection.ATeamObject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Добавление категории</title>
        <%  InitialContext initialContext;
            GoodsHome goodsHome;
            Goods goods;     
            Object homeObject;
            
            CategoryHome categoryHome;
            Category category;
            Object homeObject1;
            
            Manufacturer manufacturer;
            ManufacturerHome manufacturerHome;
            Object homeObject2;
            
            ATeamObject ato = new ATeamObject();
            
            try{
                initialContext = new InitialContext();
                homeObject = initialContext.lookup("GoodsBean");
                goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                        GoodsHome.class);
                
                homeObject1 = initialContext.lookup("CategoryBean");
                categoryHome = (CategoryHome) PortableRemoteObject.narrow(homeObject1,
                        CategoryHome.class);
                
                homeObject2 = initialContext.lookup("ManufacturerBean");
                manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(homeObject2,
                        ManufacturerHome.class);
        %>
    </head>
    <body background="1.jpg" bgproperties="fixed">
        <h4><a href="index.jsp">Главная</a></h4>
                <a href="addCategory.jsp">Добавление категории</a>
        <h1>Добавление категории</h1>
        <%  if (request.getParameter("name") != null){
                ato.setName(request.getParameter("name"));
                ato.setObjectDescription(request.getParameter("description"));
                category = categoryHome.create(ato);               
                response.sendRedirect("index.jsp");
            }
        %>
        <form action="addCategory.jsp" method="POST">
            <p>Введите название категории</p>
            <input type="text" name="name" value="" size="50" />
            <p>Введите описание категории</p>
            <input type="text" name="description" value="" size="200" />
            <p><input type="submit" value="Добавить" name="add" /></p>
        </form>
    <% } catch(Exception e){
            e.printStackTrace(System.err);
       }
    %>
    </body>
</html>
